package com.yeqian.attachment.service;

import com.baomidou.mybatisplus.extension.service.IService;
import com.yeqian.attachment.entity.AttachmentFile;
import org.springframework.web.multipart.MultipartFile;

import java.time.LocalDateTime;

public interface AttachmentService extends IService<AttachmentFile> {

    AttachmentFile uploadFile(MultipartFile file, String uploadPath, String fileType);

    /**
     * 保存数据路径及其他信息至数据库
     * @param file
     * @param uploadPath
     * @param fileType
     * @return
     */
    default AttachmentFile saveSAttachmentFile(MultipartFile file, String uploadPath, String relativepath, String fileType,String userId) {
        AttachmentFile attachmentFile = new AttachmentFile();
        attachmentFile.setFileType(fileType);
        attachmentFile.setFilePath(uploadPath);
        attachmentFile.setFileName(file.getOriginalFilename());
        attachmentFile.setRelativepath(relativepath);
        attachmentFile.setFileSize(attachmentFile.getFileSize());
        attachmentFile.setCreateUser(userId);
        attachmentFile.setCreatetime(LocalDateTime.now());
        this.save(attachmentFile);
        return attachmentFile;
    }
}
